﻿using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace Structura.WCF
{
	public class SilverlightFaultBehavior : BehaviorExtensionElement, IEndpointBehavior
	{

		public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
		{
			SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector();
			endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
		}

		// The following methods are stubs and not relevant. 

		public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
		{
		}

		public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
		{
		}


		public void Validate(ServiceEndpoint endpoint)
		{
		}

		public override Type BehaviorType
		{
			get { return typeof(SilverlightFaultBehavior); }
		}

		protected override object CreateBehavior()
		{
			return new SilverlightFaultBehavior();
		}

	}
}
